
package com.ccc.scala.base8_match

object Match08 {
  def main(args: Array[String]): Unit = {
    // 匹配对象

    // Attribute -> Object
    val user = User("CJ", 24)

    user match {
      case User("CJ", 24) => println("the user is CJ")
      case _ => println("other user")
    }
  }

  class User {
    var name: String = _
    var age: Int = _
  }

  object User {

    def unapply(user: User): Option[(String, Int)] = {
      Option((user.name, user.age))
    }

    def apply(name: String, age: Int) = {
      val user = new User()
      user.name = name
      user.age = age
      user
    }
  }

}
